import { Component, OnInit, ViewChild } from '@angular/core';
import { ApiService } from '../core/api';
import { StorageService } from '../core/sotrage/storage.service';
import { Router, ActivatedRoute } from '@angular/router';
import { ToptipsService } from 'ngx-weui';
import { I18nService } from '../core/i18n/i18n.service';

@Component({
	selector: 'app-recharge',
	templateUrl: './recharge.component.html',
	styleUrls: ['./recharge.component.less'],
})
export class RechargeComponent implements OnInit {
	dialogShow = false;
	dialog2Show = false;
    del: any;
    userDel;
    travelOrderId;
	order;
	data: any = {};
	msgData;
	constructor(
		private i: I18nService,
		private api: ApiService,
		private sto: StorageService,
        private router: Router,
		private activeRouter:ActivatedRoute,
		private toptips: ToptipsService
	) {
		this.i.get([
			'recharge-page.ts1', 
			'recharge-page.ts2', 
			'register-user'
		]).subscribe(res => {
			this.msgData = res;
		});
	}
	ngOnInit() {
        this.travelOrderId = this.activeRouter.snapshot.queryParams['travelOrderId'];
		this.del = this.sto.get('pay-data');
        // this.del.toRecharge = 'N'
        this.api.post('旅游订单详情',{travelOrderId:this.travelOrderId}).then((e:any) => {
            this.order = e.data;
          });
        this.api.post('用户详情', {}).then(res => {
			this.userDel = res['data'];
        });
	}

	closeCopyAddress() {
		this.dialogShow = false;
	}
	showCopyAddress() {
		if (this.order.reserveFee > this.userDel.userWalletForUserView.availableBalance) {
			this.toptips.warn(this.msgData['recharge-page.ts1']);
			return;
		}
		this.api.post('是否设置用户交易密码', {}).then(res => {
			if(res['data'].isTradePw === 'Y'){
				this.dialogShow = true;
			}else{
				this.dialog2Show = true;
			}
		});
	}
	toPay() {
		if(!this.data.tradePw||this.data.tradePw.length<6){
			this.toptips.warn(this.msgData['recharge-page.ts2']);
			return;
		}
		this.api.post('支付旅游订单', {travelOrderId: this.travelOrderId,tradePw:this.data.tradePw}).then((e: any) => {
            this.router.navigate(['/rechargeSuccess'], {
				queryParams: {
					travelOrderId: this.travelOrderId
				}
			});
		});
	}
	cancel(){
		this.dialogShow = false;
		this.data.tradePw = '';
	}
	closethis(){
		this.dialog2Show = false;
	}
	toSetPwd(){
		this.router.navigateByUrl('/security');
	}
	private copy():void{
	 };
}
